import {
  Observable, of,
  tap,
} from 'rxjs'

// 里面包含路由处理函数
const next = {
  handle() {
    console.log(`pay...`)
    return of('路由处理函数的返回值') // 路由处理函数返回一个可观察对象
  }
}

export class Logger1Interceptor {
  intercept(_, next): Observable<any> {
    console.log('Before1')
    const now = Date.now()
    return next.handle().pipe(
      tap({
        next: val => console.log(`After1... ${Date.now() - now}ms`, val)
      }),
    )
  }
}

new Logger1Interceptor().intercept(null, next)
  .subscribe({
    next: val => console.log(`next ${val}`),
    error: err => console.log(`error ${err}`),
    complete: () => console.log(`complete`)
  })
